package check;


import cn.hutool.core.io.FileUtil;
import config.IniDTO;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import rfid.dto.Rfid_SYGOLE_DTO;
import tools.IniReader;
import tools.OSUtil;
import tools.PathUtil;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;

@Slf4j(topic = "配置信息类")
public class Check_Info {
    public static String NATIVE_LIBRARY_NAME;

    static {
        if (OSUtil.isWindows()== true) {
            try {
                NATIVE_LIBRARY_NAME = PathUtil.getExePath() + File.separator + "config.ini";
            } catch (IOException e) {
                e.printStackTrace();
            }
        } else {
            NATIVE_LIBRARY_NAME = PathUtil.getRunPath() + File.separator + "config.ini";
        }


    }

    @SneakyThrows
    public Check_Info() {
        //  File filename = new File("config.ini");
        //  new IniReader(filename);

        File file = FileUtil.file(NATIVE_LIBRARY_NAME);
        IniReader reader = new IniReader(file);
        file = FileUtil.file(NATIVE_LIBRARY_NAME);
        reader = new IniReader(file);

        /*解析文件地址*/


//        /*巴鲁夫RFID*/
//        Rfid_BALUFF_DTO.setIp(reader.getValue("config", "--rfid-ip"));
//        Rfid_BALUFF_DTO.setPort(reader.getValue("config", "--rfid-port"));
//        Rfid_BALUFF_DTO.setRfidDeviceInfo(reader.getValue("config", "--rfid-deviceInfo"));
////        Rfid_BALUFF_DTO.setRfidDeviceInfo(reader.getValue("config", "--rfid-len"));


        /*思谷RFID配置*/
        Rfid_SYGOLE_DTO.setRfidId(reader.getValue("config", "--sg-rfid-id"));
        Rfid_SYGOLE_DTO.setIp(reader.getValue("config", "--sg-rfid-ip"));
        Rfid_SYGOLE_DTO.setPort(reader.getValue("config", "--sg-rfid-port"));
        Rfid_SYGOLE_DTO.setLen(reader.getValue("config", "--sg-rfid-len"));

        System.out.println("配置加载完毕");
        log.info("读取配置文件成功");
    }
}
